home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / GNU / GNUPLOTsrc.lha / term / eepic.trm < prev    next >
Encoding:
Text File  |  1996-01-22  |  10.1 KB  |  374 lines

  1. /*
  2.  * $Id: eepic.trm,v 1.8 1995/12/20 21:47:45 drd Exp $
  3.  *
  4.  */
  5.  
  6. /* GNUPLOT - eepic.trm */
  7. /*
  8.  * Copyright (C) 1990 - 1993   
  9.  *
  10.  * Permission to use, copy, and distribute this software and its
  11.  * documentation for any purpose with or without fee is hereby granted, 
  12.  * provided that the above copyright notice appear in all copies and 
  13.  * that both that copyright notice and this permission notice appear 
  14.  * in supporting documentation.
  15.  *
  16.  * Permission to modify the software is granted, but not the right to
  17.  * distribute the modified code.  Modifications are to be distributed 
  18.  * as patches to released version.
  19.  *  
  20.  * This software  is provided "as is" without express or implied warranty.
  21.  * 
  22.  * This file is included by ../term.c.
  23.  *
  24.  * This terminal driver supports:
  25.  *   The EEPIC macros for LaTeX. 
  26.  *
  27.  * AUTHORS
  28.  *   David Kotz
  29.  *
  30.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  31.  * 
  32.  */
  33. /*
  34.  *  This file contains the eepic terminal driver, intended for use with the 
  35.  *  eepic.sty macro package for LaTeX. This is an alternative to the 
  36.  *  latex driver. You need eepic.sty, epic.sty, and a printer driver that
  37.  *  supports the tpic \specials.
  38.  *
  39.  * Although dotted and dashed lines are possible with EEPIC, and are
  40.  * tempting, they do not work well for high-sample-rate curves, mushing
  41.  * the dashes all together into a solid line. For now anyway, the EEPIC
  42.  * driver will have only solid lines. Anyone got a solution?
  43.  *
  44.  * LATEX must also be defined.
  45.  */
  46. /*
  47.  * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
  48.  */
  49.  
  50. #ifndef GOT_DRIVER_H
  51. #include "driver.h"
  52. #endif
  53.  
  54. #ifdef TERM_REGISTER
  55. register_term(eepic)
  56. #endif
  57.  
  58. #ifdef TERM_PROTO
  59. TERM_PUBLIC void EEPIC_init __P((void));
  60. TERM_PUBLIC void EEPIC_graphics __P((void));
  61. TERM_PUBLIC void EEPIC_text __P((void));
  62. TERM_PUBLIC void EEPIC_linetype __P((int linetype));
  63. TERM_PUBLIC void EEPIC_move __P((unsigned int x, unsigned int y));
  64. TERM_PUBLIC void EEPIC_point __P((unsigned int x, unsigned int y, int number));
  65. TERM_PUBLIC void EEPIC_vector __P((unsigned int ux, unsigned int uy));
  66. TERM_PUBLIC void EEPIC_arrow __P((unsigned int sx, unsigned int sy, unsigned int ex, unsigned int ey, TBOOLEAN head));
  67. TERM_PUBLIC void EEPIC_put_text __P((unsigned int x, unsigned int y, char str[]));
  68. TERM_PUBLIC int EEPIC_justify_text __P((enum JUSTIFY mode));
  69. TERM_PUBLIC int EEPIC_text_angle __P((int angle));
  70. TERM_PUBLIC void EEPIC_reset __P((void));
  71.  
  72. #define EEPIC_PTS_PER_INCH (72.27)
  73. #define DOTS_PER_INCH (300)    /* resolution of printer we expect to use */
  74. #define EEPIC_UNIT (EEPIC_PTS_PER_INCH/DOTS_PER_INCH) /* dot size in pt */
  75.  
  76. /* 5 inches wide by 3 inches high (default) */
  77. #define EEPIC_XMAX (5*DOTS_PER_INCH)  /* (EEPIC_PTS_PER_INCH/EEPIC_UNIT*5.0) */
  78. #define EEPIC_YMAX (3*DOTS_PER_INCH)  /* (EEPIC_PTS_PER_INCH/EEPIC_UNIT*3.0) */
  79.  
  80. #define EEPIC_HTIC (5*DOTS_PER_INCH/72)        /* (5./EEPIC_UNIT) */
  81. #define EEPIC_VTIC (5*DOTS_PER_INCH/72)        /* (5./EEPIC_UNIT) */
  82. #define EEPIC_HCHAR (DOTS_PER_INCH*53/10/72)    /* (5.3/EEPIC_UNIT) */
  83. #define EEPIC_VCHAR (DOTS_PER_INCH*11/72)    /* (11./EEPIC_UNIT) */
  84. #define GOT_EEPIC_PROTO
  85. #endif
  86.  
  87. #ifndef TERM_PROTO_ONLY
  88. #ifdef TERM_BODY
  89.  
  90. static unsigned int EEPIC_posx;
  91. static unsigned int EEPIC_posy;
  92. enum JUSTIFY eepic_justify=LEFT;
  93. static int eepic_angle=0;
  94.  
  95. /* for DOTS point style */
  96. #define EEPIC_TINY_DOT "\\rule{.1pt}{.1pt}"
  97.  
  98. /* POINTS */
  99. #define EEPIC_POINT_TYPES 12    /* we supply more point types */
  100. static char GPFAR * GPFAR EEPIC_points[] = {
  101.     "\\raisebox{-1.2pt}{\\makebox(0,0){$\\Diamond$}}",
  102.     "\\makebox(0,0){$+$}",
  103.     "\\raisebox{-1.2pt}{\\makebox(0,0){$\\Box$}}",
  104.     "\\makebox(0,0){$\\times$}",
  105.     "\\makebox(0,0){$\\triangle$}",
  106.     "\\makebox(0,0){$\\star$}",
  107.     "\\circle{12}", "\\circle{18}", "\\circle{24}",
  108.     "\\circle*{12}", "\\circle*{18}", "\\circle*{24}"
  109. };
  110.  
  111. /* LINES */
  112. #define EEPIC_NUMLINES 5        /* number of linetypes below */
  113. static char GPFAR * GPFAR EEPIC_lines[] = {
  114.     "\\thicklines \\path",            /* -2 border */
  115.     "\\thinlines \\drawline[-50]",        /* -1 axes */
  116.     "\\thinlines \\path",            /*  0 solid thin  */
  117.     "\\thicklines \\path",            /*  1 solid thick */
  118.     "\\Thicklines \\path",            /*  2 solid Thick */
  119. };
  120. /* These are other possibilities
  121.     "\\thinlines \\dottedline{30}",
  122.     "\\thinlines \\drawline[-30]",    
  123.     "\\thinlines \\dottedline{60}",
  124.     "\\thinlines \\drawline[-60]",    
  125.     "\\thinlines \\dashline[-10]{20}[6]"
  126. */
  127. static int EEPIC_type;        /* current line type */
  128. static TBOOLEAN EEPIC_inline = FALSE; /* are we in the middle of a line */
  129. void EEPIC_endline __P((void)); /* terminate any line in progress */
  130. static int EEPIC_linecount = 0; /* number of points in line so far */
  131. #define EEPIC_LINEMAX 50        /* max value for linecount */
  132.  
  133. /* ARROWS */
  134. /* we use the same code as for LATEX */
  135. void best_latex_arrow __P((int sx, int sy, int ex, int ey, int who, TBOOLEAN head)); /* figure out the best arrow */
  136.  
  137. TERM_PUBLIC void EEPIC_init()
  138. {
  139.     EEPIC_posx = EEPIC_posy = 0;
  140.     EEPIC_linetype(-1);
  141.     fprintf(outfile, "%% GNUPLOT: LaTeX picture using EEPIC macros\n");
  142.     fprintf(outfile, "\\setlength{\\unitlength}{%fpt}\n", EEPIC_UNIT);
  143. }
  144.  
  145.  
  146. TERM_PUBLIC void EEPIC_graphics()
  147. {
  148.     register struct termentry *t = term;
  149.  
  150.     fprintf(outfile, "\\begin{picture}(%d,%d)(0,0)\n", t->xmax, t->ymax);
  151.     fprintf(outfile, "\\tenrm\n");
  152. }
  153.  
  154.  
  155. TERM_PUBLIC void EEPIC_text()
  156. {
  157.     EEPIC_endline();
  158.     fprintf(outfile, "\\end{picture}\n");
  159. }
  160.  
  161.  
  162. TERM_PUBLIC void EEPIC_linetype(linetype)
  163.     int linetype;
  164. {
  165.     EEPIC_endline();
  166.  
  167.     if (linetype >= EEPIC_NUMLINES-2)
  168.      linetype %= (EEPIC_NUMLINES-2);
  169.  
  170.     EEPIC_type = linetype;
  171. }
  172.  
  173.  
  174.  
  175. TERM_PUBLIC void EEPIC_move(x,y)
  176.     unsigned int x,y;
  177. {
  178.     EEPIC_endline();
  179.  
  180.     EEPIC_posx = x;
  181.     EEPIC_posy = y;
  182. }
  183.  
  184.  
  185. TERM_PUBLIC void EEPIC_point(x,y, number)        /* version of line_and_point */
  186.     unsigned int x,y;
  187.     int number;                /* type of point */
  188. {
  189.     EEPIC_move(x,y);
  190.     
  191.     /* Print the character defined by 'number'; number < 0 means 
  192.       to use a dot, otherwise one of the defined points. */
  193.     fprintf(outfile, "\\put(%d,%d){%s}\n", x, y, 
  194.           (number < 0 ? EEPIC_TINY_DOT
  195.            : EEPIC_points[number % EEPIC_POINT_TYPES]));
  196. }
  197.  
  198.  
  199. TERM_PUBLIC void EEPIC_vector(ux,uy)
  200.     unsigned int ux,uy;
  201. {
  202.     if (!EEPIC_inline) {
  203.        EEPIC_inline = TRUE;
  204.  
  205.        /* Start a new line. This depends on line type */
  206.        fprintf(outfile, "%s(%u,%u)", 
  207.              EEPIC_lines[EEPIC_type+2], 
  208.              EEPIC_posx, EEPIC_posy);
  209.        EEPIC_linecount = 1;
  210.     } else {
  211.        /* Even though we are in middle of a path, 
  212.         * we may want to start a new path command. 
  213.         * If they are too long then latex will choke.
  214.         */
  215.        if (EEPIC_linecount++ >= EEPIC_LINEMAX) {
  216.           fprintf(outfile, "\n");
  217.           fprintf(outfile, "%s(%u,%u)", 
  218.                 EEPIC_lines[EEPIC_type+2], 
  219.                 EEPIC_posx, EEPIC_posy);
  220.           EEPIC_linecount = 1;
  221.        }
  222.     }
  223.     fprintf(outfile, "(%u,%u)", ux,uy);
  224.     EEPIC_posx = ux;
  225.     EEPIC_posy = uy;
  226. }
  227.  
  228. void
  229. EEPIC_endline()
  230. {
  231.     if (EEPIC_inline) {
  232.        fprintf(outfile, "\n");
  233.        EEPIC_inline = FALSE;
  234.     }
  235. }
  236.  
  237.  
  238. TERM_PUBLIC void EEPIC_arrow(sx,sy, ex,ey, head)
  239.     unsigned int sx,sy, ex,ey;
  240.     TBOOLEAN head;
  241. {
  242.     best_latex_arrow(sx,sy, ex,ey, 2, head); /* call latex routine */
  243.  
  244.     EEPIC_posx = ex;
  245.     EEPIC_posy = ey;
  246. }
  247.  
  248.  
  249. TERM_PUBLIC void EEPIC_put_text(x, y, str)
  250.     unsigned int x,y;        /* reference point of string */
  251.     char str[];            /* the text */
  252. {
  253.     EEPIC_endline();
  254.  
  255.     fprintf(outfile, "\\put(%d,%d)",x,y);
  256.     switch(eepic_angle) {  
  257.         case 0: {
  258.           switch(eepic_justify) {
  259.              case LEFT: {
  260.                 fprintf(outfile,
  261.                        "{\\makebox(0,0)[l]{%s}}\n", str);
  262.                 break;
  263.              }
  264.              case CENTRE: {
  265.                 fprintf(outfile,
  266.                        "{\\makebox(0,0){%s}}\n", str);
  267.                 break;
  268.              }
  269.              case RIGHT: {
  270.                 fprintf(outfile,
  271.                        "{\\makebox(0,0)[r]{%s}}\n", str);
  272.                 break;
  273.              }
  274.           }
  275.           break;
  276.        }
  277.        case 1: {            /* put text in a short stack */
  278.           switch(eepic_justify) {
  279.              case LEFT: {
  280.                 fprintf(outfile,
  281.                        "{\\makebox(0,0)[lb]{\\shortstack{%s}}}\n", str);
  282.                 break;
  283.              }
  284.              case CENTRE: {
  285.                 fprintf(outfile,
  286.                        "{\\makebox(0,0)[l]{\\shortstack{%s}}}\n", str);
  287.                 break;
  288.              }
  289.              case RIGHT: {
  290.                 fprintf(outfile,
  291.                        "{\\makebox(0,0)[lt]{\\shortstack{%s}}}\n", str);
  292.                 break;
  293.              }
  294.           }
  295.           break;
  296.        }    
  297.     }
  298. }
  299.  
  300.  
  301.  
  302. TERM_PUBLIC int EEPIC_justify_text(mode)
  303.     enum JUSTIFY mode;
  304. {
  305.     eepic_justify = mode;
  306.     return (TRUE);
  307. }
  308.  
  309. TERM_PUBLIC int EEPIC_text_angle(angle)
  310.     int angle;
  311. {
  312.     /* we can't really write text vertically, but this will 
  313.       put the ylabel centred at the left of the plot, and
  314.       then we'll make a \shortstack */
  315.     eepic_angle = angle;
  316.     return (TRUE);
  317. }
  318.  
  319. TERM_PUBLIC void EEPIC_reset()
  320. {
  321.     EEPIC_endline();
  322.     EEPIC_posx = EEPIC_posy = 0;
  323. }
  324.  
  325. #endif
  326.  
  327. #ifdef TERM_TABLE
  328.  
  329. TERM_TABLE_START(eepic_driver)
  330.       "eepic", "EEPIC -- extended LaTeX picture environment",
  331.        EEPIC_XMAX, EEPIC_YMAX, EEPIC_VCHAR, EEPIC_HCHAR, 
  332.        EEPIC_VTIC, EEPIC_HTIC, options_null, EEPIC_init, EEPIC_reset, 
  333.        EEPIC_text, null_scale, EEPIC_graphics, EEPIC_move, EEPIC_vector, 
  334.        EEPIC_linetype, EEPIC_put_text, EEPIC_text_angle, 
  335.        EEPIC_justify_text, EEPIC_point, EEPIC_arrow, set_font_null
  336. TERM_TABLE_END(eepic_driver)
  337.  
  338. #undef LAST_TERM
  339. #define LAST_TERM eepic_driver
  340.  
  341. #endif
  342. #endif
  343.  
  344. /*
  345.  * NAME: eepic
  346.  *
  347.  * OPTIONS: none
  348.  *
  349.  * SUPPORTS: EEPIC -- extended LaTeX picture environment
  350.  *
  351.  * Further Info: From top of the file
  352.  *
  353.  *  This file contains the eepic terminal driver, intended for use with the 
  354.  *  eepic.sty macro package for LaTeX. This is an alternative to the 
  355.  *  latex driver. You need eepic.sty, epic.sty, and a printer driver that
  356.  *  supports the tpic \specials.
  357.  *
  358.  * Although dotted and dashed lines are possible with EEPIC, and are
  359.  * tempting, they do not work well for high-sample-rate curves, mushing
  360.  * the dashes all together into a solid line. For now anyway, the EEPIC
  361.  * driver will have only solid lines. 
  362.  *
  363.  *         My additions:
  364.  * If your device driver doesn't support tpic \specials you can use
  365.  * the eepicemu.sty which will enable you to use some of them.
  366.  *
  367.  * There is another gnuplot driver (tpic) that supports dashed lines but
  368.  * cannot be used if your DVI driver doesn't support tpic \specials.
  369.  *
  370.  * eepic.sty might be obsoleted by a new picture package for LaTeX2e. 
  371.  * I'm not even sure that eepic and 2e can work together (outside 2e's
  372.  * compatibility mode).
  373.  */
  374.